﻿package plugin.instances.game
{
    import com.core.*;
    import com.sh.game.util.*;
    import consts.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import plugin.ybstore.consts.*;
    import uiresource.instances.ui.*;
    import view.mornExtends.*;
    import vo.*;

    public class FbkGame extends FbkUI implements IInstance
    {
        private var _instance:Object;

        public function FbkGame()
        {
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            this._instance = param1;
            this.showItem(param1.show);
            this.showBuy(param1.buy);
            if (param2[InstancesPublic.MONSTERNUM])
            {
                this.updateShow(InstancesPublic.MONSTERNUM, param2[InstancesPublic.MONSTERNUM]);
            }
            btn_quit.filters = [];
            return;
        }// end function

        public function showBuy(param1:String) : void
        {
            var _loc_2:* = param1.split("#");
            var _loc_3:Array = [];
            while (_loc_2.length > 0)
            {
                
                _loc_3.push({id:_loc_2.shift(), storeId:_loc_2.shift()});
            }
            list2.array = _loc_3;
            list2.renderHandler = new Handler(this.buyRender);
            return;
        }// end function

        private function buyRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Label = null;
            if (param2 < list2.length)
            {
                _loc_3 = list2.array[param2];
                _loc_4 = ConfigDictionary.data.item;
                (param1.getChildByName("fi") as FlashItem).data = ItemObject.create(_loc_4[_loc_3.id]);
                _loc_5 = param1.getChildByName("txt_buy") as Label;
                _loc_5.addEventListener(MouseEvent.CLICK, this.doBuy);
                _loc_5.dataSource = _loc_3;
            }
            return;
        }// end function

        protected function doBuy(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget.dataSource;
            PluginManager.instance.sendToServer("store", CMDStore.GetPrice, _loc_2.storeId);
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            switch(param1)
            {
                case InstancesPublic.TIMECHECKER:
                {
                    txt_time.text = "倒计时：" + TimeDataFormatUtil.getLeftTime(int(param2));
                    break;
                }
                case InstancesPublic.MONSTERNUM:
                {
                    if (param2.bossnumber == 0)
                    {
                        txt_msg.text = "击杀小怪:<font color=\'#" + (param2.allNumber == param2.killnumber ? ("52b335") : ("c62440")) + "\'>(" + param2.killnumber + "/" + param2.allNumber + ")</font>";
                    }
                    else if (param2.allNumber == 0)
                    {
                        txt_msg.text = "击杀" + this._instance.boss + ":<font color=\'#" + (param2.bknumber == param2.bossnumber ? ("52b335") : ("c62440")) + "\'>(" + param2.bknumber + "/" + param2.bossnumber + ")</font>";
                    }
                    else
                    {
                        txt_msg.text = "击杀" + this._instance.boss + ":<font color=\'#" + (param2.bknumber == param2.bossnumber ? ("52b335") : ("c62440")) + "\'>(" + param2.bknumber + "/" + param2.bossnumber + ")</font><br>击杀小怪:<font color=\'#" + (param2.allNumber == param2.killnumber ? ("52b335") : ("c62440")) + "\'>(" + param2.killnumber + "/" + param2.allNumber + ")</font>";
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function showItem(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", "/", "#");
            list0.array = _loc_3[0];
            list0.renderHandler = new Handler(this.itemRender, [list0]);
            if (_loc_3[1])
            {
                list1.array = _loc_3[1];
                list1.renderHandler = new Handler(this.itemRender, [list1]);
            }
            return;
        }// end function

        private function itemRender(param1:List, param2:Component, param3:int) : void
        {
            if (param3 < param1.length)
            {
                (param2 as FlashItem).data = param1.array[param3];
            }
            return;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            return;
        }// end function

        public function initEvent() : void
        {
            ModelProxy.change("guideitem", "guideid" + GuideType.GUIDE_FB, btn_quit);
            btn_quit.clickHandler = new Handler(this.doQuit);
            return;
        }// end function

        private function doQuit() : void
        {
            ModelProxy.change("zone", "exitInstance", null);
            ModelProxy.change("guide", "hide", GuideType.GUIDE_FB);
            return;
        }// end function

        public function removeEvent() : void
        {
            return;
        }// end function

    }
}
